/**
 * 李珂<likenamehaojie@hotmail.com>
 *     20170401
 */
import Vue from 'vue';
import App from './App';
import router from './router';
import ElementUI from 'element-ui';
// import { Button, Select, Upload, Tabs, TabPane, Form, FormItem, Switch,} from 'element-ui';


import VueResource from 'vue-resource';
import VueBlu from 'vue-blu';
// import 'element-ui/lib/index.js';
import 'vue-blu/dist/css/vue-blu.min.css';
import 'vue-blu/dist/fonts/fontawesome-webfont.woff'
import Vuex from 'vuex';
import cfg from 'properties';
// for Vue 2.0
import VueLazyload from 'vue-lazyload/vue-lazyload';
//import 'element-ui/lib/theme-default/index.css';    // 默认主题
// import '../static/css/theme-green/index.css';       // 浅绿色主题
 import '../static/css/custom/index.css';       // 浅绿色主题
import store from '../src/store/store';
import qs from 'qs';
import $ from './util/jquery-1.12.4.min';
import MuseUI from 'muse-ui'
import 'muse-ui/dist/muse-ui.css'

import VueWebsocket from "vue-websocket";
import lodopCom from './components/common/lodop'
// import lodop from './util/LodopFuncs'
Vue.use(MuseUI);
Vue.use(ElementUI);
Vue.use(VueResource);
Vue.use(Vuex);
Vue.use(VueBlu);
Vue.use(lodopCom);

// Vue.use(Button);
// Vue.use(Select);
// Vue.use(Upload);
// Vue.use(Tabs);
// Vue.use(TabPane);
// Vue.use(Form);
// Vue.use(FormItem);
// Vue.use(Switch);

Vue.use(VueLazyload, {
    error: 'dist/error.png',
    loading: 'dist/loading.gif',
    try: 3 // default 1
})

 router.beforeEach((to, from, next) => {
    //解除非VUE管理的事件监听避免重复绑定
     $("#content").off('scroll');
     next();
})
router.afterEach(route => {
    //alert(1)
})
window._VUE_STORE_ = store;
let instanceVue = new Vue({
    router,
    render: h => h(App),
    store,

}).$mount('#app');
$.prototype.scrollHeight = function () {
    return $(this)[0].scrollHeight;
}

let ws = '';
var url = cfg.ws_url;
if (!url) {
    alert('Select whether to use W3C WebSocket or SockJS');

}else {

    ws = (url.indexOf('sockjs') != -1) ?
        new SockJS(url, undefined, {protocols_whitelist: transports}) : new WebSocket(url);

    ws.onopen = function () {
        //setConnected(true);
        console.log('Info: connection opened.');
    };
    ws.onmessage = function (event) {
        console.log(event.data);
        console.log('Received: ' + event.data);

        if(event.data.indexOf("*update*")>=0){//强制系统检查更新并升级
            // alert("系统发生重大升级");
            const ipc = window.require('electron').ipcRenderer;
            ipc.send('check-for-update')

        }
    };
    ws.onclose = function (event) {
        setConnected(false);
        console.log('Info: connection closed.');
        console.log(event);
    }
}
function disconnects() {
    if (ws != null) {
        ws.close();
        ws = null;
    }

}
/* window.unbeforeunload =disconnect() */

$(window).unload(function(){
    disconnects()
    //alert("获取到了页面要关闭的事件了！");
});
import axioxs from '../src/util/http';
Vue.prototype.$axioxs = axioxs;
Vue.prototype.$qs = qs;
Vue.prototype.$cfg = cfg;
Vue.prototype.$$ = $;
Vue.prototype.$ws = ws;
// Vue.prototype.$lodop = lodop;

